﻿
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Models.Common;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Security.Cryptography.Xml;
using UtilsBase;
using System.Composition;
using ServiceWeb.DBGateway;
using UtilsORM;
using UtilsORM.MySqlData;
using GatewayServer.Common;

namespace GatewayServer.Controllers
{
    public class DeviceValueWarnController : BaseMagerController
    {
        EFYihongIotContext ef = new EFYihongIotContext();
        // GET: Mager_Department
        public IActionResult list(IFormCollection FC, HttpReqModel httpRequest, iot_device reqobj, int PageIndex = 1, int PageSize = 15, string type = "1")
        {
            ViewData["reqobj"] = reqobj;
            List<SugarParameter> sugarParameters = new List<SugarParameter>();
            int totalRecord = 0;
            string sqlwhere = "  ";
            if (!string.IsNullOrEmpty(httpRequest.name))
            {
                sqlwhere = sqlwhere + " and d_name like CONCAT('%',@name,'%') ";
                sugarParameters.Add(new SugarParameter("name", httpRequest.name));

            }
            if (!string.IsNullOrEmpty(reqobj.d_code))
            {
                sqlwhere = sqlwhere + " and d_code=@d_code ";
                sugarParameters.Add(new SugarParameter("d_code", reqobj.d_code));

            }


            if (!string.IsNullOrEmpty(FC["hid_pageIndex"]))
            {
                PageIndex = int.Parse(FC["hid_pageIndex"].ToString());

            }

            sqlwhere = sqlwhere + "  ";
            string sql = "select  d.d_p_model_no,d.d_id,d_code,d_guid,d_name,c.vc_key,c.vc_name,c.vc_value,c.vc_add_time from iot_device d inner join iot_device_model on d_model_guid=m_guid\r\nleft join iot_device_value_current c on vc_d_guid=d_guid where m_code=1039    " + sqlwhere;
            DataTable dt = MySqlYihongIot.getPageDataTable(PageIndex, PageSize, sql, sugarParameters, "vc_add_time desc", ref totalRecord);


            ViewData["DataList"] = dt;

            ViewBag.PageSize = PageSize;
            ViewBag.RecordCount = totalRecord;//总条数
            ViewBag.PageCount = totalRecord % PageSize == 0 ? totalRecord / PageSize : totalRecord / PageSize + 1;//分的页数
            ViewBag.PageIndex = PageIndex;//当前页码
            return View(httpRequest);
        }
        public IActionResult ListDialog(string type)
        {
            ViewBag.Type = type;
            return View();
        }



    }
}